n=int(input())
nums=list(map(int,input().split()))

tickets=[0 for i in range(0,101)]

def display(a,b):
    for i in range(a,b):
        print(i,end=" ")

for num in nums:
    flag=False

    for j in range(0,20):
        k=j*5+1
        if num==5:
            if sum(tickets[k:k+5])==0:
                flag=True
                display(k,k+5)
                tickets[k:k+5]=[1 for i in range(0,5)]
                break
        elif num==4:
            if sum(tickets[k:k+4])==0:
                flag=True
                display(k,k+4)
                tickets[k:k+4]=[1 for i in range(0,4)]
                break
            elif sum(tickets[k+1:k+5])==0:
                flag=True
                display(k+1,k+5)
                tickets[k+1:k+5]=[1 for i in range(0,4)]
                break
        elif num==3:
            if sum(tickets[k:k+3])==0:
                flag=True
                display(k,k+3)
                tickets[k:k+3]=[1 for i in range(0,3)]
                break
            elif sum(tickets[k+1:k+4])==0:
                flag=True
                display(k+1,k+4)
                tickets[k+1:k+4]=[1 for i in range(0,3)]
                break
            elif sum(tickets[k+2:k+5])==0:
                flag=True
                display(k+2,k+5)
                tickets[k+2:k+5]=[1 for i in range(0,3)]
                break
        elif num==2:
            if sum(tickets[k:k+2])==0:
                flag=True
                display(k,k+2)
                tickets[k:k+2]=[1 for i in range(0,2)]
                break
            elif sum(tickets[k+1:k+3])==0:
                flag=True
                display(k+1,k+3)
                tickets[k+1:k+3]=[1 for i in range(0,2)]
                break
            elif sum(tickets[k+2:k+4])==0:
                flag=True
                display(k+2,k+4)
                tickets[k+2:k+4]=[1 for i in range(0,2)]
                break
            elif sum(tickets[k+3:k+5])==0:
                flag=True
                display(k+3,k+5)
                tickets[k+3:k+5]=[1 for i in range(0,2)]
                break
        else:
            break

    if flag==False:
        while num>0:
            for i in range(1,101):
                if tickets[i]==0:
                    print(i,end=" ")
                    tickets[i]=1
                    break
            num-=1
    
    print("")
